public class Main {
    class Solution {
        public int minOperations(int[] nums, int x) {
            //求和
            int sum = 0;
            for(int i = 0;i < nums.length; i++){
                sum = sum + nums[i];
            }
            //转换解题目标
            int target = sum - x;
            if(target < 0){
                return -1;
            }
            sum = 0;
            int ret = -1;
            for(int left = 0,right = 0;right < nums.length;right++){
                //入窗口
                sum = sum + nums[right];
                //判断
                while(sum > target){
                    //出窗口
                    sum = sum - nums[left];
                    left++;
                }
                //更新
                if(sum == target){
                    ret = Math.max(ret, right - left + 1);
                }
            }
            return ret == -1? -1 : nums.length-ret;
        }
    }
    public static void main(String[] args) {
    }
}